package lab03.test07;

import java.io.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipInputStream;

/**
 * Created by V555 on 2017/12/19.
 */
public class Test {
    public static void main(String[] args) {
        String path="D:\\book.zip";
        File file=null;
        ZipInputStream zipInputStream=null;
        InputStream inputStream=null;
        FileOutputStream fileOutputStream=null;
        ZipEntry zipEntry=null;
        try {
            ZipFile zipFile=new ZipFile(path);
            zipInputStream=new ZipInputStream(new FileInputStream(path));
            while ((zipEntry=zipInputStream.getNextEntry())!=null){
                System.out.println("压缩文件名为"+zipEntry.getName());
                file=new File("D:\\book"+File.separator+zipEntry.getName());
                file.createNewFile();

                inputStream=zipFile.getInputStream(zipEntry);
                fileOutputStream=new FileOutputStream(file);
                int ch=0;
                while ((ch=inputStream.read())!=-1){
                    fileOutputStream.write(ch);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
